package dao;

import dao.Entity.Reservations;
import dao.Entity.Reservation;
import java.sql.*;

public class QueryReservations {

    public static Reservations getResult(int i, String param) {
        MyConnection myCon = new MyConnection();
        myCon.getConnection();
        Reservations reservations = null;
        try {
            PreparedStatement ps;
            if (i == 2) {
                ps = myCon.connection.prepareStatement(
                        "SELECT * FROM appointment where AppointmentCheckStatus=2;");
            } else if (i == 0) {
                ps = myCon.connection.prepareStatement(
                        "SELECT * FROM appointment where AppointmentCheckStatus=0 or AppointmentCheckStatus=1;");
            } else if (i == 3) {
                ps = myCon.connection.prepareStatement(
                        "SELECT * FROM appointment where placeTimenumber=? and AppointmentTime>=CURRENT_DATE();");
                ps.setString(1, param);
            } else {
                ps = myCon.connection.prepareStatement(
                        "SELECT * FROM appointment;");
            }
            ResultSet rs = ps.executeQuery();
            reservations = new Reservations();
            while (rs.next()) {
                reservations.addReservation(new Reservation(rs.getInt(1), rs.getString(2),
                        rs.getString(3), rs.getString(4), rs.getInt(5),
                        rs.getString(6), rs.getString(7)));
            }
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            myCon.closeConnection();
        }
        return reservations;
    }
}
